var selectId = '';
var selectSubId = '';
var openFlg = 0;
// 一级菜单修改背景颜色
function changeBackground(id) {
	// 处理旧的
	if (selectId != '') {
		try {
			// 还原背景色
			document.all("item_" + selectId).style.background = "#fff"; // #2a68c9
			document.all("item_" + selectId).style.color = "#000";// #007bff
			document.all("item_icon_" + selectId).style.color = "#000";// #007bff
			document.all("item_endicon_" + selectId).style.color = "#000";// #007bff
			document.all("itemMenu_" + selectId).style.display = "none";
		} catch (e) {
		}
	}
	// 设定新的
	if (id != '') {
		try {
			document.all("item_" + id).style.background = "#007bff";// #007bff
			document.all("item_" + id).style.color = "#fff";// #007bff
			document.all("item_icon_" + id).style.color = "#fff";// #007bff
			document.all("item_endicon_" + id).style.color = "#fff";// #007bff
			// 打开菜单
			document.all("itemMenu_" + id).style.display = "";
			document.all("itemMenu_" + id).style.color = "#000";// #007bff
			/*document.all("itemMenu_" + id).style.transition = "all .5s ease 0s";*/
			openFlg = 1;
		} catch (e) {
		}
	}
	selectId = id;
}
// 二级菜单修改背景颜色
function changeBackgroundSub(subId) {
	// 处理旧的
	if (selectSubId != '') {
		try {
			// 还原背景色
			document.all("itemSub_" + selectSubId).style.background = "";// #2a68c9
			document.all("itemSub_" + selectSubId).style.color = "#666";// #007bff
		} catch (e) {
		}
	}
	// 设定新的
	if (subId != '') {
		try {
			document.all("itemSub_" + subId).style.background = "#00A0F0";// #007bff  03A9F4
			document.all("itemSub_" + subId).style.color = "#fff";// #007bff
		} catch (e) {
		}
	}
	selectSubId = subId;
}

// 提示信息
function showMessage(code, message) {
	if (code == '1') {// 警告
		showMessageByType('1', '4', message);
	} else {
		var arr = message.split(":");
		showMessageByType('0', arr[0], arr[1]);
	}
}
function showMessageByType(code, type, message) {
	if (type == '' || message == "")
		return;
	else if (type == '1') {// 成功
		document.all("messagetyle").className = "alert alert-success";
		document.all(" messagetitle").innerText = "【成功】  ";
		document.all("messagelbl").innerText = message;
		document.all("messagebox").style.display = "";
	} else if (type == '2') {// 提示
		document.all("messagetyle").className = "alert alert-info";
		document.all("messagetitle").innerText = "【提示】  ";
		document.all("messagelbl").innerText = message;
		document.all("messagebox").style.display = "";
	} else if (type == '3') {// 警告
		document.all("messagetyle").className = "alert alert-warning";
		document.all("messagetitle").innerText = "【警告】  ";
		document.all("messagelbl").innerText = message;
		document.all("messagebox").style.display = "";
	} else if (type == '4') {// 注意、错误
		document.all("messagetyle").className = "alert alert-danger";
		document.all("messagetitle").innerText = "【注意】  ";
		document.all("messagelbl").innerText = message;
		document.all("messagebox").style.display = "";
	} else {

	}
	window.setTimeout(function() {
		document.all("messagebox").style.display = "none";
	}, 3000);
}

// 页面刷新
function changeForm(urlpath, title, navbar) {
	showPageForm(urlpath);
	changeNavbar(title, navbar);
}

function changeNavbar(title, navbar) {
	// 更新功能显示名字
	document.all("title").innerText = title;
	// 更新导航条
	document.all("navbar").innerText = navbar;
}

// 高度修正
function resizeIFrame() {
	var screen_width = document.documentElement.clientWidth;
	var screen_height = document.documentElement.clientHeight;

	var cur_width = 1200;
	var cur_height = 600;
	var cur_width_fix = 100;
	var cur_height_fix = 60;

	// 计算高度
	{
		var mb = myBrowser();
		console.log(screen_height);
		console.log(mb);
		// 处理浏览器差异的13个像素
		if ("IE" == mb) {
			cur_height = screen_height - cur_height_fix - 27;
		} else if ("FF" == mb) {
			cur_height = screen_height - cur_height_fix;
		} else if ("Chrome" == mb) {
			cur_height = screen_height - cur_height_fix;
		} else if ("Opera" == mb) {
			cur_height = screen_height - cur_height_fix;
		} else if ("Safari" == mb) {
			cur_height = screen_height - cur_height_fix;
		}
	}

	document.all("mainFormTable").style.height = cur_height + "px";

	document.getElementById("messagebox").style.width = (screen_width * 0.4) + "px";
}

// 动态修正高度
// resizeIFrame();

function showConfirmInfo(url, msg) {
	$('#myModalLabel').empty().text("确认");
	$('#defaultMessage').empty().text("即将进行以下重要操作，请确认！");
	$('#deleteWarningMessage').empty().text("【" + msg + "】");
	$("#deleteWarningModalDeleteButton").attr("onclick", "doDeleteRequest('" + url + "')");
	$("#deleteWarningModal").modal('show');
}
function showDeleteWarning(url, msg) {
	$('#myModalLabel').empty().text("警告");
	$('#defaultMessage').empty().text("删除之后数据可能无法恢复，确认删除吗?");
	$('#deleteWarningMessage').empty().text("【" + msg + "】");
	$("#deleteWarningModalDeleteButton").attr("onclick", "doDeleteRequest('" + url + "')");
	$("#deleteWarningModal").modal('show');
}

function doDeleteRequest(url) {
	$("#deleteWarningModal").modal("hide");
	showPageForm(url);
}

// 只区分浏览器，不考虑版本
function myBrowser() {
	var userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串
	var isOpera = userAgent.indexOf("Opera") > -1;
	if (isOpera) {
		return "Opera"
	}
	// 判断是否Opera浏览器
	else if (userAgent.indexOf("Firefox") > -1) {
		return "FF";
	} // 判断是否Firefox浏览器
	else if (userAgent.indexOf("Chrome") > -1) {
		return "Chrome";
	} else if (userAgent.indexOf("Safari") > -1) {
		return "Safari";
	} // 判断是否Safari浏览器
	else if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
		return "IE";
	}
	// 判断是否IE浏览器
}
